﻿<?php
	session_start();
	require_once("../includes/db_connect.php");
	
	if($_SESSION["classId"]) {
		$courseQuery = mysqli_query($db, "SELECT id, name, classId FROM courses WHERE classId = '{$_SESSION["classId"]}'" );
	}else{
		$courseQuery = mysqli_query($db, "SELECT id, name, classId FROM courses" );
	}
	echo "<table>";
	while($course = $courseQuery->fetch_assoc()) {
		$classId = $course["classId"];
		$courseId = $course["id"];
		
		$classQuery = mysqli_query($db, "SELECT * FROM users WHERE id = '{$_SESSION["id"]}'");
			
		echo "<tr><td>";
		echo $course["name"];
		echo "</td>";	
		$gradeQuery = mysqli_query($db, "SELECT moment, grade FROM grades WHERE courseId = '$courseId' AND userId = {$_SESSION["id"]}");
	
		echo "<td>";
		
		if($grade = $gradeQuery->fetch_assoc()) {
			switch($grade["grade"]) {
				case 0:
					echo "IG";
					break;
				case 1:
					echo "G";
					break;
				case 2:
					echo "VG";
					break;
				default:
					echo "UNKNOWN";
					break;				
			}
		}else{
			echo "-";
		}
		echo "</td></tr>";
	}
	echo "</table>";
?>